/**
 * Copyright (C) 2018 - 2020 https://github.com/LeeYan9
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.service.impl;

import com.bifrost.entity.SkuShipment;
import com.bifrost.model.vo.PageVO;
import com.bifrost.repository.SkuShipmentRepository;
import com.bifrost.service.SkuShipmentService;
import com.bifrost.service.StoreService;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lee
 * Create Class on 2018/8/30
 * @com.bifrost.service.impl
 * @wechat-mall
 */
@Service
public class SkuShipmentServiceImpl implements SkuShipmentService {

    @Autowired
    SkuShipmentRepository skuShipmentRepository;
    @Autowired
    StoreService storeService;
    @Override
    public PageVO page(Long storeId, Integer page, Integer size) {
        return null;
    }

    @Override
    public List list(Long storeId) {
        List<SkuShipment> skuShipments = skuShipmentRepository.findAllByMerchantStore(storeService.getMerchantStore(storeId));
        Assert.notEmpty(skuShipments,"门店没有运费模板信息");

        ArrayList<Map> shipModels = Lists.newArrayList();
        skuShipments.forEach(skuShipment -> {
            HashMap<String, Object> map = new HashMap<>();
            map.put("skuShipmentId",skuShipment.getSkuShipmentId());
            map.put("templateName",skuShipment.getTemplateName());
            shipModels.add(map);
        });

        return shipModels;
    }

}
